package edu.thu.studio.ormdesigner.editor.palette;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.ConnectionCreationToolEntry;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.SelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.SimpleFactory;
import org.eclipse.jface.resource.ImageDescriptor;

import edu.thu.studio.ormdesigner.Activator;
import edu.thu.studio.ormdesigner.model.diagram.node.TableNode;
import edu.thu.studio.ormdesigner.model.diagram.node.ViewNode;
import edu.thu.studio.ormdesigner.util.Properties;

public class ORMPaletteRoot extends PaletteRoot {
    
    public ORMPaletteRoot() {
        createControlGroup(this);
        createComponentsDrawer(this);
    }
    
    private void createControlGroup(PaletteRoot root) {
        PaletteGroup controlGroup = new PaletteGroup(Properties.palette_label_tool);
        
        ToolEntry tool = new SelectionToolEntry();
        controlGroup.add(tool);
        root.setDefaultEntry(tool);
        
        tool = new ConnectionCreationToolEntry(Properties.palette_label_reference,
            Properties.palette_label_create_reference, null, null, null);
        controlGroup.add(tool);
        
        root.add(controlGroup);
    }
    
    private void createComponentsDrawer(PaletteRoot root) {
        
        PaletteDrawer drawer = new PaletteDrawer(Properties.palette_label_node);
        
        ToolEntry tool = new CombinedTemplateCreationEntry(Properties.palette_label_table,
            Properties.palette_label_create_table, TableNode.class, new SimpleFactory(TableNode.class), null, null);
        ImageDescriptor imageDescriptor = Activator.getImageDescriptor(Properties.icon_table_add);
        tool.setSmallIcon(imageDescriptor);
        tool.setLargeIcon(imageDescriptor);
        drawer.add(tool);
        tool = new CombinedTemplateCreationEntry(Properties.palette_label_view, Properties.palette_label_create_view,
            ViewNode.class, new SimpleFactory(ViewNode.class), null, null);
        imageDescriptor = Activator.getImageDescriptor(Properties.icon_table_link);
        tool.setSmallIcon(imageDescriptor);
        tool.setLargeIcon(imageDescriptor);
        drawer.add(tool);
        
        root.add(drawer);
        
    }
    
}
